	
	cap log close

*******************************************************************
/* title: eodb_replication_robustness_1_coup_activity_3_model_specification_Poisson_ZINB.do */
/* description: robustness analysis from economic origins of dictatorship and democracy testing ZINB and Poisson models */
/* authors: dan slater, ben smith, gautam nair */
*******************************************************************

	clear
	set mem 500m
	set more off
	pause on 
	vers 10.0

*******************************************************************
* SET DIRECTORY & USE DATASET
*******************************************************************

	* set directory to folder containing replication data
	* cd 
	use "eodb_replication_data.dta"

*******************************************************************
* MODELS: ZINB
*******************************************************************

	eststo clear
	
	* defining controls
	# delimit ;
	local controls_all 
	am_inc_gdp_ratio_l1
	wdi_ny_gdp_mktp_kd_zg_l1
	pwt_lngdppc_l1
	pwt_kg_l1
	undp_manufacturing_share_l1 
	wdi_ny_gdp_totl_rt_zs_l1 
	wdi_log_population_l1 
	wdi_sp_pop_dpnd_ol_l1 
	pwt_openk_l1
	region_democ_cgv_gwf_l1
	coup_success_yrs_free_l1 
	time_trend_linear_l1 
	time_trend_quadratic_l1 
	time_trend_cubic_l1
	;
	# delimit cr

	# delimit ;
	local controls_subsample 
	am_inc_gdp_ratio_l1
	wdi_ny_gdp_mktp_kd_zg_l1
	pwt_kg_l1
	undp_manufacturing_share_l1 
	wdi_ny_gdp_totl_rt_zs_l1 
	wdi_log_population_l1 
	wdi_sp_pop_dpnd_ol_l1 
	pwt_openk_l1
	region_democ_cgv_gwf_l1
	coup_success_yrs_free_l1 
	time_trend_linear_l1 
	time_trend_quadratic_l1 
	time_trend_cubic_l1
	;
	# delimit cr

	egen nonmissing= rownonmiss(`controls_all')
	egen nonmissingmax=max(nonmissing) if nonmissing!=.
	qui sum nonmissingmax
	local completedata="`r(max)'"
	keep if nonmissing==nonmissingmax

	* coup success + regime transition
	nbreg coup_success_gwf `controls_all' if year!=1972, cluster(ccode) iterate(50) irr
	cap drop yhat
	predict yhat
	summarize yhat, d
	tab country if yhat>0.01 & yhat!=.
	by ccode: egen any_coup=max( coup_success)
	tab any_coup if yhat>0.01
	sum yhat if oecd_member==1	
	sum yhat if country=="United States", d
	sum yhat if country=="United Kingdom", d

	zinb coup_success_gwf `controls_all', inflate(pwt_lngdppc_l1) iterate(50)vuong irr
	zinb coup_success_gwf `controls_subsample', inflate(pwt_lngdppc_l1) iterate(50)vuong irr
	eststo: zinb coup_success_gwf `controls_subsample', inflate(pwt_lngdppc_l1) iterate(50) cluster(ccode) irr

	* coup success
	nbreg coup_success_n `controls_all', cluster(ccode) iterate(50) irr
	cap drop yhat
	predict yhat
	summarize yhat, d
	zinb coup_success_n `controls_all', inflate(pwt_lngdppc_l1) iterate(50) vuong
	zinb coup_success_n `controls_subsample', inflate(pwt_lngdppc_l1) iterate(50) vuong
	eststo: zinb coup_success_n `controls_subsample', inflate(pwt_lngdppc_l1) iterate(50)cluster(ccode)

	* coup attempt
	nbreg coup_attempt_n `controls_all', cluster(ccode) iterate(50) irr
	cap drop yhat
	predict yhat
	summarize yhat, d
	zinb coup_attempt_n `controls_all', inflate(pwt_lngdppc_l1) iterate(50)irr vuong
	zinb coup_attempt_n `controls_subsample', inflate(pwt_lngdppc_l1) iterate(50) irr vuong
	eststo: zinb coup_attempt_n `controls_subsample', inflate(pwt_lngdppc_l1) iterate(50) irr

	* coup plots + rumors
	nbreg coup_plot_rumor_n `controls_all', cluster(ccode) iterate(50) irr
	cap drop yhat
	predict yhat
	summarize yhat, d

	zinb coup_plot_rumor_n `controls_all', inflate(pwt_lngdppc_l1) iterate(50) vuong irr
	zinb coup_plot_rumor_n `controls_subsample', inflate(pwt_lngdppc_l1) iterate(50) vuong irr
	eststo: zinb coup_plot_rumor_n `controls_subsample', inflate(pwt_lngdppc_l1) iterate(50) irr
/*
*******************************************************************
* MODELS: POISSON
*******************************************************************

	* coup success + regime transition
	eststo: zip coup_success_gwf `controls_subsample', cluster(ccode) iterate(50) inflate(pwt_lngdppc_l1) irr
	
	* coup success
	eststo: zip coup_success_n `controls_subsample', cluster(ccode) iterate(50) inflate(pwt_lngdppc_l1) irr
	
	* coup attempt
	eststo: zip coup_attempt_n `controls_subsample',  cluster(ccode) iterate(50) inflate(pwt_lngdppc_l1) irr
	
	* coup plots + rumors
	eststo: zip coup_plot_rumor_n `controls_subsample',  cluster(ccode) iterate(50) inflate(pwt_lngdppc_l1) irr

*******************************************************************
* MODELS: LOGIT
*******************************************************************

	* coup success + regime transition
	eststo: logit coup_success_gwf `controls_all', cluster(ccode) iterate(50) 
	
	estout using "eodb_replication_robustness_1_coup_activity_3_model_specification_Poisson_ZINB.xls", replace cells(b(fmt(%9.3f) star) se(par(`"="("' `")""') fmt(3)) ) stats(N N_clust, fmt(0 0)) style(tab) starlevels(* 0.10 ** 0.05 *** 0.01)  eform
	estout using "eodb_replication_robustness_1_coup_activity_3_model_specification_Poisson_ZINB_pvals.xls", replace cells(b(fmt(%9.3f) star) se(par(`"="("' `")""') fmt(3)) p(fmt(3)) ) stats(N N_g, fmt(0 0)) style(tab) starlevels(* 0.10 ** 0.05 *** 0.01)

*******************************************************************
* LOG CLOSE
*******************************************************************
	
	* log close

